<?php

date_default_timezone_set('America/Sao_Paulo');

require 'library/Doctrine/Common/ClassLoader.php';

$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', 'library');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'library/Doctrine');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('DoctrineExtensions', 'library');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Entities', 'Model');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Repositories', 'Model');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('App');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Service');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Foxframe', 'library');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Foxforms', 'library');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Helper', 'library');
$classLoader->register();

use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Configuration;
use Foxframe\Registry;

defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'prod'));

if (APPLICATION_ENV == 'dev')
{
	ini_set("display_errors", "on");
	$cache = new \Doctrine\Common\Cache\ArrayCache;
// $dbParams = array(
// 	'host'			=> 'localhost',
// 	'driver'		=> 'pdo_mysql',
// 	'user'			=> 'root',
// 	'password'		=> 'root',
// 	'dbname'		=> 'foxsisco_wireframe',
// 	'charset'		=> 'utf8',
// 	'driverOptions'	=> array(
// 		\PDO::MYSQL_ATTR_INIT_COMMAND	=>'SET NAMES utf8',
// 	)
// );
}
else
{
	ini_set("display_errors", "off");
	$cache = new \Doctrine\Common\Cache\ApcCache;
}

// the connection configuration
// $dbParams = array(
// 	'host'			=> 'www.foxsis.com',
// 	'driver'		=> 'pdo_mysql',
// 	'user'			=> 'foxsisco_foxweb',
// 	'password'		=> 'VamosTomarUmaStella2013',
// 	'dbname'		=> 'foxsisco_wireframe',
// 	'charset'		=> 'utf8',
// 	'driverOptions'	=> array(
// 		\PDO::MYSQL_ATTR_INIT_COMMAND	=>'SET NAMES utf8',
// 	)
// );
$dbParams = array(
	'host'			=> 'www.foxsis.com',
	'driver'		=> 'pdo_mysql',
	'user'			=> 'foxsisco_avifran',
	'password'		=> 'FrangoGrelhado@)!#',
	'dbname'		=> 'foxsisco_wireavifran',
	'charset'		=> 'utf8',
	'driverOptions'	=> array(
		\PDO::MYSQL_ATTR_INIT_COMMAND	=>'SET NAMES utf8',
	)
);


$config	= Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), APPLICATION_ENV == 'dev');
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$config->setProxyDir('Model/Proxies');
$config->setProxyNamespace('Proxies');

if (APPLICATION_ENV == 'dev')
	$config->setAutoGenerateProxyClasses(true);
else
	$config->setAutoGenerateProxyClasses(false);

$em		= EntityManager::create($dbParams, $config);
$conn	= \Doctrine\DBAL\DriverManager::getConnection($dbParams, $config);

//Adicionando instância do entityManager no Registry
Registry::getInstance()->set('entityManager', $em);
Registry::getInstance()->set('conn', $conn);

// use Doctrine\ORM\Proxy\Autoloader;
// $proxyDir = "Proxies";
// $proxyNamespace = "Proxies";
// Autoloader::register($proxyDir, $proxyNamespace);
